<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Laravel\Lumen\Routing\Controller;

class BaseController extends Controller
{
    //
    /**
     * 成功返回Json数据
     * @param string $message 提示信息
     * @param array $data 数据
     * @param int $code 成功返回时的代码
     * @return \Illuminate\Http\JsonResponse
     */
    public function jsonResponse($message = '', $data = [], $code = 0)
    {
        if(empty($message)&&!empty($code)){
            $message=config('error')[(int) $code];
        }
        return response()->json([
            'code'    => $code,
            'message' => $message,
            'data'    => $data,
        ]);
    }

    public function getPageSize(Request $request)
    {
        return $request->input('page_size', config('app.app_rows'));
    }
}
